package crp.core.workflow.domain.models;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

import java.util.Map;
import java.util.Objects;

@Getter
@Builder
@AllArgsConstructor
public class WorkflowCandidate {
    private static final Map<WorkflowCandidateType, String> SHORT_MAPPING = Map.of(
            WorkflowCandidateType.USER, "U",
            WorkflowCandidateType.GROUP, "G",
            WorkflowCandidateType.DEPARTMENT, "D",
            WorkflowCandidateType.PERMISSION, "P"
    );


    private final WorkflowCandidateType type;
    private final String target;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        WorkflowCandidate that = (WorkflowCandidate) o;
        return type == that.type
                && Objects.equals(target, that.target);
    }

    @Override
    public int hashCode() {
        return Objects.hash(type, target);
    }

    @Override
    public String toString() {
        return String.format("%s_%s", SHORT_MAPPING.get(type), target);
    }
}
